import { BaseApi } from "@/api-services/apis/baseApi";
import { SysUser, SysRole } from "@/api-services/models/system";
import { ExcelImportResult } from "@/api-services/models/system/excelImportResult";
import { BaseIdInput } from "@/api-services/models/baseModels";
import { SqlSugarPagedList, UnifyResult } from "@/api-services/unifyResult";

/**
 * 用户管理Api
 */
class SysUserApi extends BaseApi<SysUser.SysUser, SysUser.SysUser, SysUser.SysUser> {
  //批量导入
  batchImport = async (data: FormData) => {
    return this.normalPost<ExcelImportResult>(`/batchImport`, data);
  };
  //模板下载
  templateDownload = async () => {
    return this.normalGetBlob(`/templateDownload`, null);
  };
  errorFileDownload = async (data: BaseIdInput) => {
    return this.normalGetBlob(`/errorDownload`, data);
  };
  //重置密码
  resetPassword = async (data: BaseIdInput) => {
    return this.normalPost(`/resetPassword`, data);
  };
  //解锁用户
  unLockUser = (data: BaseIdInput) => {
    return this.normalPost<string>("/unLockUser", data);
  };
  //修改密码
  changePassword = async (data: SysUser.ChangePwdInput) => {
    return this.normalPost(`/changePassword`, data);
  };
  //改变用户状态
  changeStatus = async (data: BaseIdInput) => {
    return this.normalPost(`/changeStatus`, data);
  };
  //授权
  grantRole = async (data: SysUser.UserRoleInput) => {
    return this.normalPost(`/grantRole`, data);
  };
  //用户已授权角色列表
  roleList = async (id: object) => {
    return this.normalGet<Array<SysRole.RoleSelectorOutput>>(`/roleList`, id);
  };
  userSelector = async (data: object) => {
    return this.normalGet<UnifyResult<SqlSugarPagedList<SysUser.UserSimpleInfo>>>(`/userSelector`, data);
  };
}

export default new SysUserApi("/system/user");
